package com.megvii.dzh.spider.common.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Configuration {
  /**
   * Swagger ui 页面显示信息
   */
  private final String SWAGGER2_API_TITLE = "爬虫控制器"; // 标题
  private final String SWAGGER2_API_BASEPACKAGE = "com.megvii";
  private final String SWAGGER2_API_DESCRIPTION = "";
  private final String SWAGGER2_API_CONTACT = "超允.chen";
  private final String SWAGGER2_API_VERSION = "1.0";

  /**
   * createRestApi
   *
   * @return
   */
  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
      .apis(RequestHandlerSelectors.basePackage(SWAGGER2_API_BASEPACKAGE)).paths(PathSelectors.any()).build();
  }

  /**
   * apiInfo
   * 
   * @return
   */
  private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title(SWAGGER2_API_TITLE).description(SWAGGER2_API_DESCRIPTION)
      .contact(SWAGGER2_API_CONTACT).version(SWAGGER2_API_VERSION).build();
  }
}
